package flexcloud.controls.cumulusClasses
{

import flash.display.BlendMode;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

public class Tag extends Sprite {
	
	//--------------------------------------------------------------------------
	//
	//  Constructor
	//
	//--------------------------------------------------------------------------
	
	public function Tag(data:Object, format:TextFormat) {
		super();
		
		_data = data;
		
		// initialize the text field
		textField.autoSize = TextFieldAutoSize.LEFT;
		textField.selectable = false;
		
		textField.defaultTextFormat = format;
		//textField.embedFonts = true;
		
		addChild(textField);
		
		// handle Flash events
		addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
		addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
	}
	
	//--------------------------------------------------------------------------
	//
	//  Variables
	//
	//--------------------------------------------------------------------------
	
	private var textField:TextField = new TextField();
	
	//--------------------------------------------------------------------------
	//
	//  Overridden properties
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  x
    //----------------------------------
	
	override public function set x(value:Number):void
	{
		super.x = value - textField.width * 0.5;
	}
	
    //----------------------------------
    //  y
    //----------------------------------
	
	override public function set y(value:Number):void
	{
		super.y = value - textField.height * 0.5;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Properties
	//
	//--------------------------------------------------------------------------
	
    //----------------------------------
    //  active (read-only)
    //----------------------------------
    
	private var _active:Boolean = false;
	
    public function get active():Boolean
    {
        return _active;
    }
	
    //----------------------------------
    //  text
    //----------------------------------
	
	public function get backgroundColor():uint {
		return textField.backgroundColor;
	}
	
	public function set backgroundColor(value:uint):void {
		textField.backgroundColor = value;
	}
	
    //----------------------------------
    //  cx
    //----------------------------------
    
	private var _cx:Number;
	
    public function get cx():Number
    {
        return _cx;
    }
    
    public function set cx(value:Number):void
    {
        _cx = value;
    }
	
    //----------------------------------
    //  cy
    //----------------------------------
    
	private var _cy:Number;
	
    public function get cy():Number
    {
        return _cy;
    }
    
    public function set cy(value:Number):void
    {
        _cy = value;
    }
	
    //----------------------------------
    //  cz
    //----------------------------------
    
	private var _cz:Number;
	
    public function get cz():Number
    {
        return _cz;
    }
    
    public function set cz(value:Number):void
    {
        _cz = value;
    }
	
    //----------------------------------
    //  data (read-only)
    //----------------------------------
    
	private var _data:Object;
	
    public function get data():Object
    {
        return _data;
    }
	
    //----------------------------------
    //  text
    //----------------------------------
	
	public function get text():String {
		return textField.text;
	}
	
	public function set text(value:String):void {
		textField.text = value;
	}
	
	//--------------------------------------------------------------------------
	//
	//  Overridden methods
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Methods
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Overridden event handlers
	//
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//
	//  Event handlers
	//
	//--------------------------------------------------------------------------
	
	private function rollOutHandler(e:Event):void
	{
		_active = false;
		textField.background = false;
	}
	
	private function rollOverHandler(e:Event):void
	{
		_active = true;
		textField.background = true;
	}
	
}

}